<?php
//生成账单类
namespace app\api\service;
use think\App;
use think\Controller;
class Calcaccount extends Controller
{
	private $uid;//用户id
	private $huanNum;//还款笔数
	private $days;//还款总天数
	private $payment;//渠道参数
	private $rate;//还款费率
	private $cardInfo;//信用卡信息
	private $minMoney;
	private $maxMoney;

	private $minNum;//最小还款笔数
	private $maxNum;//最大还款笔数
	private $money;//账单金额
	public function initialize($uid){
		$this->uid=$uid;
		$this->huanNum=input('post.type');
		//检查数据是否符合要求
		$checkRes = $this->check();
		if($checkRes !== true){
			return $checkRes;
		}
	}

	//主函数
	public function main(){
		//生成账单
		$accountData=$this->createAccount();
		return $accountData;
	}


	public function check(){
		$post = input("post.");
		$pay_id = $post['pay_id'];//渠道id
		$cid = $post['cid'];//信用卡id
		$repayAmount = $post['money'];//还款或者自定义金额
		$type = intval($post['type']);//还款笔数
		$version = $post['version'];//app版本
		$region = $post['region'];//地区
		$city_id = $post['city_id'];//城市id
		$start_time = $post['start_time'];//开始时间
		$end_time = $post['end_time'];//结束时间
		if ($version != '2.0') {
			return '请联系客服或更新app';
		}
		if (empty($repayAmount)) {
			return  '还款金额必填填写';
		}
		if($type<1){
			return "请输入大于1的还款笔数";
		}
		if (empty($start_time)) {
			return '开始日期必填填写';
		}
		if (empty($end_time)) {
			return '结束日期必填填写';
		}
		//开始时间不能小于当天时间
		if (strtotime(date('Y-m-d', time())) > strtotime($start_time)) {
			return '开始日期不能小于当天日期';
		}
		//结束日期必须大于开始日期
		if (strtotime($start_time) > strtotime($end_time)) {
			return '结束日期必须大于开始日期';
		}
		//获取各种必要信息，通道信息，信用卡信息，费率
		$this->payment = $this->getPayment();
		//计算账单日
		$this->diffBetweenTwoDays();

		//开始检查笔数是否合理
		return $this>checkHuanNum();
	}


	//检查用户输入的还款笔数是否合理
	public function checkHuanNum(){
		$minNum=$this->createMinNum();
		$maxNum=$this->createMaxNum();
		if($this->huanNum<$minNum){
			return "此笔数低于最小值,最小笔数为".$minNum;
		}
		if($this->huanNum>$minNum){
			return "此笔数超过过最大笔数,最大笔数为".$maxNum;
		}
		return true;
	}

	//生成账单
	public function createAccount(){
		return true;
	}

	//计算最小笔数
	public function createMinNum(){

	}

	//计算最大笔数
	public function createMaxNum(){

	}

	//产生列表
	public function createList(){
		$minNum = $this->createMinNum();
		$maxNum = $this->createMaxNum();
	}


	private function diffBetweenTwoDays(){
		$s_date = input("post.start_time");
		$e_date = input("post.end_time");
		$s_date_new = $s_date;
		if (date("H") >= 18 && date("Y-m-d", strtotime("$s_date")) == date("Y-m-d")) {
			$s_date_new = date("Y-m-d", strtotime("+1 day", strtotime("$s_date")));
		}
		$this->days = diffBetweenTwoDays($s_date_new,$e_date);
	}

	//获取通道信息
	private function getPayment(){

	}

}